/*
 * jxDao Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxDao.dao;

import java.util.Collection;
import java.util.List;

import org.jxDao.dao.exception.JXDaoException;
import org.jxDao.dao.filter.Filterable;
import org.jxDao.dao.filter.GroupBy;
import org.jxDao.dao.filter.OrderBy;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxDao
 * @package org.jxDao.dao
 * @date 11/04/2014 - 10:14:10
 * @param <Bean>
 */
public interface Dao<Bean extends Persistable> {
	
	/**
	 * 
	 */
	void abortOperation();
	
	/**
	 * @throws ClassNotFoundException
	 * @throws JXDaoException
	 */
	void beginTransaction() throws ClassNotFoundException, JXDaoException;
	
	/**
	 * @throws JXDaoException
	 */
	void commitTransaction() throws JXDaoException;
	
	/**
	 * @return the number of beans from a table
	 * @throws JXDaoException
	 */
	long count() throws JXDaoException;
	
	/**
	 * @param filter
	 * @return the number of beans from a table
	 * @throws JXDaoException
	 */
	long count(Filterable filter) throws JXDaoException;
	
	/**
	 * Delete all beans
	 * 
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteAll() throws JXDaoException;
	
	/**
	 * @param filter
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByFilter(Filterable filter) throws JXDaoException;
	
	/**
	 * @param bean
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByPK(Bean bean) throws JXDaoException;
	
	/**
	 * @param beans
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByPK(Bean[] beans) throws JXDaoException;
	
	/**
	 * @param beans
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByPK(Collection<Bean> beans) throws JXDaoException;
	
	/**
	 * @param beans
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByPKNotIn(Bean[] beans) throws JXDaoException;
	
	/**
	 * @param beans
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int deleteByPKNotIn(Collection<Bean> beans) throws JXDaoException;
	
	/**
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int dropTable() throws JXDaoException;
	
	/**
	 * @param bean
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the Bean
	 * @throws JXDaoException
	 */
	Bean fillWithFetch(Bean bean, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getAll(Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param groupBy
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the all beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getAll(GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param groupBy
	 * @param orderBy
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the all beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getAll(GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param orderBy
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the all beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getAll(OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @return the Bean Class
	 */
	Class<?> getBeanClass();
	
	/**
	 * @param filter
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByFilter(Filterable filter) throws JXDaoException;
	
	/**
	 * @param filter
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByFilter(Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByLimit(int limit, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param filter
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByLimit(int limit, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param groupBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByLimit(int limit, GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param groupBy
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByLimit(int limit, GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByLimit(int limit, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param bean
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the bean or null
	 * @throws JXDaoException
	 */
	Bean getByPK(Bean bean, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Bean[] beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Bean[] beans, GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Bean[] beans, GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Bean[] beans, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Collection<Bean> beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Collection<Bean> beans, GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Collection<Bean> beans, GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPK(Collection<Bean> beans, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Bean[] beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Bean[] beans, GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Bean[] beans, GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Bean[] beans, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Collection<Bean> beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Collection<Bean> beans, GroupBy groupBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param groupBy
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Collection<Bean> beans, GroupBy groupBy, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param orderBy
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getByPKNotIn(Collection<Bean> beans, OrderBy orderBy, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param fieldName
	 * @return the column name or null
	 */
	String getColumnByField(String fieldName);
	
	/**
	 * @param limit
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getFirst(int limit, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param filter
	 *        without ORDER BY
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getFirst(int limit, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getLast(int limit, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param limit
	 * @param filter
	 *        without ORDER BY
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return the beans in {@link List}
	 * @throws JXDaoException
	 */
	List<Bean> getLast(int limit, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @return Operation Was Aborted
	 */
	boolean isOperationWasAborted();
	
	/**
	 * @throws JXDaoException
	 */
	void rollbackTransaction() throws JXDaoException;
	
	/**
	 * @param bean
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Bean bean, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param bean
	 * @param filter
	 *        used only in update action, never used the insert action.
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Bean bean, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Bean[] beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param filter
	 *        used only in update action, never used the insert action.
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Bean[] beans, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Collection<Bean> beans, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @param beans
	 * @param filter
	 *        used only in update action, never used the insert action.
	 * @param fetch
	 *        Example: {ObjA.class, ObjB.class, ObjC.class}
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int save(Collection<Bean> beans, Filterable filter, Class<?>... fetch) throws JXDaoException;
	
	/**
	 * @return transactionIsOpen
	 * @throws JXDaoException
	 */
	boolean transactionIsOpen() throws JXDaoException;
	
	/**
	 * Truncate table
	 * 
	 * @param cascade
	 * @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
	 * @throws JXDaoException
	 */
	int truncate(boolean cascade) throws JXDaoException;
}
